class Solution {
    public List<String> letterCombinations(String digits) {
        List<String> combinations = new ArrayList<>();
        if (digits.length() == 0) {
            return combinations;
        }
        Map<Character, String> phoneMap = new HashMap<>() {{
            put('2', "abc");
            put('3', "def");
            put('4', "ghi");
            put('5', "jkl");
            put('6', "mno");
            put('7', "pqrs");
            put('8', "tuv");
            put('9', "wxyz");
        }};
        combinations.add("");
        for (int i = 0; i < digits.length(); i++) {
            List<String> list = new ArrayList<>();
            for (char c : phoneMap.get(digits.charAt(i)).toCharArray()) {
                list.addAll(combinations.stream().map(s -> s + c).collect(Collectors.toList()));
            }
            combinations = list;
        }
        return combinations;
    }
}